//
//  KCMeetingController.swift
//  MyKC
//
//  Created by yy on 2017/3/14.
//  Copyright © 2017年 com.yasuo. All rights reserved.
//

import UIKit

class KCMeetingController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        getData()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationController?.navigationBar.subviews[0].alpha = 0
    }
    
    // MARK: -  懒加载基本属性
    var typeString: String?
    
    lazy var bgImageView: UIImageView = {
        let bgImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 64))
        let image = UIImage(named: "导航栏")
        let strImg = image?.stretchableImage(withLeftCapWidth: Int(image!.size.width * 0.5), topCapHeight: Int(image!.size.height * 0.5))
        bgImageView.image = strImg
        return bgImageView
    }()
    
    lazy var tableView: UITableView = {
        let tb = UITableView(frame: CGRect(x: 0, y: 64, width: ScreenWidth, height: ScreenHeight - 64))
        tb.delegate = self
        tb.dataSource = self
        return tb
    }()
    
}

// MARK: -  设置基本界面
extension KCMeetingController {
    internal func setupUI() {
        view.backgroundColor = UIColor.white
        //添加界面
        view.addSubview(bgImageView)
        view.addSubview(tableView)
//        automaticallyAdjustsScrollViewInsets = false
        title = typeString
        tableView.tableFooterView = UIView()
        tableView.register(UINib(nibName: "KCTypeSelectCell", bundle: nil), forCellReuseIdentifier: "KCTypeSelectCellId")
        tableView.register(UINib(nibName: "KCTypeEnumCell", bundle: nil), forCellReuseIdentifier: "KCTypeEnumCellId")
    }
}

// MARK: -  实现tableView代理方法
extension KCMeetingController: UITableViewDelegate,UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return section == 1 ? 2 : 1
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let identifier = getIdentifier(indexPath: indexPath)
        let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath)
        setupCell(indexPath: indexPath, cell: cell)
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    private func getIdentifier(indexPath: IndexPath) -> String {
        return indexPath.section == 0 ? "KCTypeEnumCellId" : "KCTypeSelectCellId"
    }
    
    private func setupCell(indexPath: IndexPath,cell: UITableViewCell) {
        cell.selectionStyle = .none
        if indexPath.section == 0 {
            let typeEnumCell = cell as? KCTypeEnumCell
            typeEnumCell?.lbe_type.text = typeString
        }
        else {
            let typeSelectCell = cell as? KCTypeSelectCell
            let titleArray = [[""],["开始时间","结束时间"],["工作内容"]]
            let title = titleArray[indexPath.section][indexPath.row]
            typeSelectCell?.lbe_desc.text = title
            typeSelectCell?.lbe_placehold.text = "请选择" + title
            typeSelectCell?.indexPath = indexPath
            typeSelectCell?.closureBlock = { index in
                if index?.section == 1 && indexPath.row == 0 {
                    
                }
                else if indexPath.section == 1 && indexPath.row == 1 {
                    
                }
                else {
                    
                }
            }
        }
    }
    
    
    
}

// MARK: -  获取网络数据
extension KCMeetingController {
    internal func getData() {
        
    }
}


